<template>
<el-col :span="24">
  <el-row> 
    <el-col :span="24"><div class="grid-content">
      <el-col :span="12">
        <el-input v-model="filters[0].value" placeholder="搜索框"></el-input>  
      </el-col>
      &nbsp;&nbsp;<el-button type="primary" @click="dialogFormVisible = true">新增条目</el-button>
        <data-tables :data="data" :filters="filters" :action-col="actionCol">
          <el-table-column v-for="title in titles" :prop="title.prop" :label="title.label" :key="title.prop"   sortable="custom" >
          </el-table-column>
        </data-tables>
      </div></el-col>
  </el-row>


  <el-dialog title="修改字段" :visible.sync="dialogFormVisible">
    <el-form :model="form">
      <el-form-item label="业务名" :label-width="formLabelWidth">
        <el-input v-model="form.name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="访问地址" :label-width="formLabelWidth">
        <el-input v-model="form.url" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="请求方式" :label-width="formLabelWidth">
        <el-input v-model="form.mode" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="input">确 定</el-button>
    </div>
  </el-dialog>
</el-col>

</template>

<script>
// import Modal from '@/components/Modal';
import { url, UrlPost, UrlDel } from '@/api/query'
// import  qs from 'qs';
export default {
  data() {
    return {
      show: true,
      // centerDialogVisible: false,
      dialogFormVisible: false,
      form: {
          name: '',
          url: '',
          mode:'',
          // date1: '',
          // date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        formLabelWidth: '120px',
      data: [
      ],
      titles: [{
        prop: 'name',
        label: '业务名'
      },{
        prop: 'url',
        label: '访问地址'
      },{
        prop: 'mode',
        label: '请求方式'
      }],
      actionCol: {
              label: '操作',
              props: {
                align: 'center',
              },
              buttons: [{
                props: {
                  type: 'primary',
                  icon: 'el-icon-edit'
                },
                handler: row => {
                  this.dialogFormVisible = true
                  console.log(row);
                  this.form.name = row.name
                  this.form.url = row.url
                  this.form.mode = row.mode
                },
                label: 'Edit'
              }, {
                handler: row => {
                  this.data.splice(this.data.indexOf(row), 1),
                  console.log(row.name)
                  this.$message('dep_name: '+row.name+'删除完毕')
                  var param={dep_name : row.name}
                  console.log(param);
                  UrlDel(param).then(response => {
                    console.log(response.data)
                    location.reload();
                  })
                },
                label: 'delete'
              }]
            },
      filters: [
        {
          prop: 'name',
          value: '',       
        }
      ],
      
    }
  },
  created() {    
    this.url()  
  },
	methods: {
    url() {
      url().then(response => {
        console.log(response.data)
        this.data = response.data
      })
    },
    input() {
      UrlPost({ "dep_name": this.form.name,"dep_url": this.form.url,"dep_mode":this.form.mode }).then(response => {
        console.log(response.data)
        // this.data = response.data
        location.reload();
      })
    },
    // UrlDelPost() {
    //   UrlDelPost({ "dep_name": this.form.name,"dep_url": this.form.url,"dep_mode":this.form.mode }).then(response => {
    //     console.log(response.data)
    //     // this.data = response.data @click="input"
    //     location.reload();
    //   })
    // },
},
}
</script>
<style>
</style>